//
//  LGInspectionReportCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/9/11.
//

#import "LGInspectionReportCell.h"

@interface LGInspectionReportCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIImageView *warningView;
/**   */
@property (nonatomic , strong)UIImageView *tipView;
/**   */
@property (nonatomic , strong)UIView *lineView;

@end

@implementation LGInspectionReportCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setType:(NSString *)type{
    _type = type;
    if([type isEqualToString:@"top"]){
        //第一个
        self.lineView.hidden = NO;
        self.baseView.layer.cornerRadius = 15;
        [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(viewPix(20));
            make.bottom.equalTo(self.contentView).offset(-viewPix(10));
        }];
        [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(viewPix(8));
            make.bottom.equalTo(self.contentView).offset(viewPix(16));
        }];
    }else if ([type isEqualToString:@"middle"]){
        //中间
        self.lineView.hidden = NO;
        self.baseView.layer.cornerRadius = 0;
        [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(viewPix(10));
            make.bottom.equalTo(self.contentView).offset(-viewPix(10));
        }];
        [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(-viewPix(16));
            make.bottom.equalTo(self.contentView).offset(viewPix(16));
        }];
    }else if ([type isEqualToString:@"bottom"]){
        //底部
        self.lineView.hidden = YES;
        self.baseView.layer.cornerRadius = 15;
        [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(viewPix(10));
            make.bottom.equalTo(self.contentView).offset(-viewPix(25));
        }];
        [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(-viewPix(16));
            make.bottom.equalTo(self.contentView).offset(-viewPix(13));
        }];
    }else{
        self.lineView.hidden = YES;
        self.baseView.layer.cornerRadius = 15;
        [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(viewPix(20));
            make.bottom.equalTo(self.contentView).offset(-viewPix(25));
        }];
        [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(viewPix(8));
            make.bottom.equalTo(self.contentView).offset(-viewPix(13));
        }];
    }
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.titleLabel.text = LGNSString(dataDic[@"exams_code_str"]);
    self.warningView.hidden = (LGNSString(dataDic[@"warnitmes"]).length>0)?NO:YES;
    [self.titleLabel lineSpacing:3];
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.warningView];
    [self.contentView addSubview:self.tipView];
    [self.contentView addSubview:self.lineView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.top.equalTo(self.contentView).offset(viewPix(8));
        make.bottom.equalTo(self.contentView).offset(viewPix(16));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(20));
        make.left.equalTo(self.contentView).offset(viewPix(28));
        make.right.equalTo(self.contentView).offset(-viewPix(65));
        make.bottom.equalTo(self.contentView).offset(viewPix(10));
    }];
    [self.warningView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.tipView.mas_left).offset(-viewPix(6));
        make.centerY.equalTo(self.titleLabel);
        make.width.height.equalTo(@(viewPix(12)));
    }];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(28));
        make.width.height.equalTo(@(viewPix(12)));
        make.centerY.equalTo(self.titleLabel);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(28));
        make.right.equalTo(self.contentView).offset(-viewPix(28));
        make.bottom.equalTo(self.contentView);
        make.height.equalTo(@(0.5));
    }];
}
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}


-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _titleLabel;
}

-(UIImageView *)warningView{
    if(!_warningView){
        _warningView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"检查报告-异常项"]];
    }
    return _warningView;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip12"]];
    }
    return _tipView;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
